package com.credithc.customers.manager.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.customers.base.ro.SmsSendFlowRo;
import com.credithc.customers.base.vo.SmsSendFlowVo;
import com.credithc.customers.manager.service.SmsFlowService;
import com.credithc.customers.manager.service.impl.AuthorizationServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title:
 * @Author: fby
 * @Date: 2020/03/24 09:56
 * @Description: com.credithc.customers.manager.controller
 * @Version: V1.0.0
 */
@RestController
@RequestMapping("/manager/yzt/v1")
public class CustomerUnifySmsFlowController {
    @Autowired
    MessageFactory messageFactory;
    @Autowired
    SmsFlowService smsFlowService;
    @Autowired
    AuthorizationServiceImpl authorizationService;

    /**
     * @description: 短信发送流水展示
     * @Author: fby
     * @Date: 2020/06/01 14:19
     * @return: com.credithc.baseserv.core.message.Message
     */
    @GetMapping("/smsSendFlow")
    public Message getSmsSendFlow(@RequestHeader("token") String token, @PathParam("caller") String caller, HttpServletRequest request, @PathParam("requestNo") String requestNo, @PathParam("systemSign") String systemSign, @PathParam("subSystemSign") String subSystemSign, @PathParam("phone") String phone, @PathParam("status") Integer status, @PathParam("createTimeStart") String createTimeStart, @PathParam("createTimeEnd") String createTimeEnd, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        SmsSendFlowRo ro = new SmsSendFlowRo();
        ro.setRequestNo(requestNo);
        ro.setSystemSign(systemSign);
        ro.setSubSystemSign(subSystemSign);
        ro.setPhone(phone);
        ro.setStatus(status);
        ro.setCreateTimeStart(createTimeStart);
        ro.setCreateTimeEnd(createTimeEnd);
        ro.setPageNo(pageNo);
        ro.setPageSize(pageSize);
        if (StringUtils.isNotBlank(caller) && "TENANT".equals(caller)) {
            List<String> productCodes = authorizationService.authChannelRo(token,request);
            ro.setChannelNos(productCodes);
        }
        PageInfo<SmsSendFlowVo> list = smsFlowService.getSmsSendFlow(ro);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);

    }

    @GetMapping("/smsSendFlow/romove")
    public Message deleteLockSts(@RequestParam("phone") String phone, @RequestParam("subSystemSign") String subSystemSign) {
        smsFlowService.deleteLockSts(phone,subSystemSign);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }
}
